﻿@{
    Layout = null;
}
@model System.Collections.IEnumerable
<!DOCTYPE html>

<html>
@Html.Partial("LoadPanelPartial")
<head>
 <title></title>
    @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
                        new Script { ExtensionType = ExtensionType.ListBox }
)

    <script>

        function treeInit(s, e) {
            var nos = $('#hidDeptPosition').val();
            if (nos != "") {
                var noArray = nos.split("&");
                for (var i = 0; i < noArray.length; i++) {
                    var node = LeftTreeView.GetNodeByName(noArray[i]);
                    if (node) {
                        node.SetChecked(true);
                    }
                }
            }
        }


        var deptPositionNo;
        var deptPositionName;
        function OK() {
            deptPositionNo = new Array();
            deptPositionName = new Array();

            GetCheckNodes(LeftTreeView);
            parent.PositionOK(deptPositionNo, deptPositionName);
        }

        function GetCheckNodes(parent) {
            var ids;
            var names;
            var preNode;
            var node;
            for (var i = 0; i < parent.GetNodeCount(); i++) {
                node = parent.GetNode(i);
                if (node.GetChecked()) {
                    ids = node.name;
                    if (ids.indexOf("%!^") != 0) {
                        deptPositionNo.push(ids);
                        names = node.GetText();
                        preNode = node.parent;
                        var str = ":";
                        while (null != preNode) {
                            names = preNode.GetText() + str + names;
                            preNode = preNode.parent;
                            str = "->";
                        }
                        deptPositionName.push(names);
                    }
                }

                if (node.GetCheckState() == "Checked" || node.GetCheckState() == "Indeterminate") {
                    if (node.GetNodeCount() != 0) {
                        GetCheckNodes(node);
                    }
                }

            }
        }
    </script>

</head>
<body>
  <div class="leftPanel">
        @Html.DevExpress().TreeView(settings =>
{
    settings.Name = "LeftTreeView";
    settings.ShowTreeLines = true;
    settings.AllowSelectNode = true;
    settings.NameField = "Id";
    settings.TextField = "Name";
    settings.ClientSideEvents.Init = "function(s, e) { treeInit(s,e) }";
    settings.EnableAnimation = false;
    settings.EnableClientSideAPI = true;
    settings.CheckNodesRecursive = true;
    settings.AllowCheckNodes = true;
    settings.AllowSelectNode = false;
    settings.PreRender = (source, e) =>
    {
        ASPxTreeView treeView = (ASPxTreeView)source;
        //treeView.ExpandAll();
    };

}).Bind(Model).GetHtml()
    </div>
    <br />
    @* @Html.DevExpress().Button(settings =>
{
    settings.Name = "btnOK";
    settings.Text = "确定";
    settings.ControlStyle.CssClass = "left";
    settings.ClientSideEvents.Click = "OK";
}).GetHtml()
    @Html.DevExpress().Button(settings =>
      {
          settings.Name = "btnCancel";
          settings.Text = "取消";
          settings.ControlStyle.CssClass = "left";
          settings.ClientSideEvents.Click = "function(){parent.PositionCancel();}";
      }).GetHtml()*@
    @Html.Hidden("hidDeptPosition", ViewData["deptPosition"])

    <script>
        lp.Hide();
    </script>

</body>
</html>
